package list;

/**题目：删除链表里面的数字
 * @Author Gavin
 * @date 2022.01.02 22:12
 */
public class list_7 {
    //Time:O(n) Space:O(1)
    public ListNode solution(ListNode head,int val){
        if(head==null)return null;
        ListNode dummy=new ListNode(-1);
        dummy.next=head;
        ListNode p=dummy;
        while (p.next!=null){
            if(p.next.val==val)p.next=p.next.next;
            else p=p.next;
        }
        return dummy.next;
    }
}
